from cassacoproject.cassaco.models import Mode
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required

@login_required
def new(request):
    mode = Mode()
    mode.description = request.POST['description']
    mode.user = request.user
    mode.save()
    return HttpResponse(mode.id)

@login_required
def getHTMLSelect(request, id):
    subcategories = Mode.objects.filter(user=request.user)
    output = '<select name="mode_id" id="modeSelect"><option>--'
    output += '<option value="new">New mode...'
    for c in subcategories:
        selected = ''
        if c.id == int(id):
            selected = 'selected'
        output += '<option %s value="%d">%s' % (selected, c.id, c.description)
    output += '</select>'
    return HttpResponse(output)